package leetCode;

public class t19 {
    public static void main(String[] args) {
        ListNode node=new ListNode(1,new ListNode(2,new ListNode(3,new ListNode(4,new ListNode(5,null)))));
        new Solution19().removeNthFromEnd(node,2);
    }

}
class Solution19 {
    public ListNode removeNthFromEnd(ListNode head, int n) {
        ListNode dummyNode=new ListNode(0,head);
        ListNode curNode=dummyNode;
        ListNode fastNode=dummyNode;
        for (int i=0;i<n;i++){
            fastNode=fastNode.next;

        }
        while (fastNode.next!=null){

                fastNode=fastNode.next;
                curNode=curNode.next;

        }
        curNode.next=curNode.next.next;
        return dummyNode.next;

    }
}